<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of inCell</title>
  <meta name="keywords" content="inCell">
  <meta name="description" content="Find cell in mesh Mobj containing point (xpt,ypt)">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">fvcom_prepro</a> &gt; inCell.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for fvcom_prepro&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>inCell
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>Find cell in mesh Mobj containing point (xpt,ypt)</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [cell]  = inCell(Mobj,xpt,ypt) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> Find cell in mesh Mobj containing point (xpt,ypt)

 function [cell]  = inCell(Mobj,xpt,ypt)

 DESCRIPTION:
   Find cell in mesh Mobj containing point (xpt,ypt)

 INPUT
    Mobj = Matlab mesh object
    xpt = x position of point
    ypt = y position of point

 OUTPUT:
    cell = cell number (=0 if not found in mesh) 

 EXAMPLE USAGE
    cell = inCell(Mobj,5.,6.)

 Author(s):  
    Geoff Cowles (University of Massachusetts Dartmouth)

 Revision history
   
==============================================================================</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [cell]  = inCell(Mobj,xpt,ypt)</a>
0002 
0003 <span class="comment">% Find cell in mesh Mobj containing point (xpt,ypt)</span>
0004 <span class="comment">%</span>
0005 <span class="comment">% function [cell]  = inCell(Mobj,xpt,ypt)</span>
0006 <span class="comment">%</span>
0007 <span class="comment">% DESCRIPTION:</span>
0008 <span class="comment">%   Find cell in mesh Mobj containing point (xpt,ypt)</span>
0009 <span class="comment">%</span>
0010 <span class="comment">% INPUT</span>
0011 <span class="comment">%    Mobj = Matlab mesh object</span>
0012 <span class="comment">%    xpt = x position of point</span>
0013 <span class="comment">%    ypt = y position of point</span>
0014 <span class="comment">%</span>
0015 <span class="comment">% OUTPUT:</span>
0016 <span class="comment">%    cell = cell number (=0 if not found in mesh)</span>
0017 <span class="comment">%</span>
0018 <span class="comment">% EXAMPLE USAGE</span>
0019 <span class="comment">%    cell = inCell(Mobj,5.,6.)</span>
0020 <span class="comment">%</span>
0021 <span class="comment">% Author(s):</span>
0022 <span class="comment">%    Geoff Cowles (University of Massachusetts Dartmouth)</span>
0023 <span class="comment">%</span>
0024 <span class="comment">% Revision history</span>
0025 <span class="comment">%</span>
0026 <span class="comment">%==============================================================================</span>
0027 tri    = Mobj.tri;
0028 nElems = Mobj.nElems;
0029 x      = Mobj.x;
0030 y      = Mobj.y;
0031 cell   = 0;
0032 xc     = Mobj.xc;
0033 yc     = Mobj.yc;
0034 dist   = sqrt(  (xc-xpt).^2 + (yc-ypt).^2);
0035 
0036 cell = 0;
0037 <span class="comment">%try nearest</span>
0038 [rmin,imin] = min(dist); 
0039 <span class="keyword">if</span>(isintriangle(x(tri(imin,1:3)),y(tri(imin,1:3)),xpt,ypt));  
0040   cell = imin; 
0041   <span class="keyword">return</span>; 
0042 <span class="keyword">end</span>;
0043 
0044 <span class="comment">%sort from min distance to max and search along sort</span>
0045 [distsort,ind] = sort(dist,1,<span class="string">'ascend'</span>);
0046 <span class="keyword">for</span> i=1:nElems
0047    <span class="keyword">if</span>(isintriangle(x(tri(ind(i),1:3)),y(tri(ind(i),1:3)),xpt,ypt));  
0048      cell = ind(i); 
0049      <span class="keyword">return</span>
0050    <span class="keyword">end</span>;
0051 <span class="keyword">end</span>;
0052   
0053 <span class="comment">% didn't find cell, just return nearest cell</span>
0054 <span class="comment">%cell = ind(1);</span></pre></div>
<hr><address>Generated on Wed 02-Nov-2011 21:58:00 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>